package ms.unicorn.util;

import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.TreeMap;

import ms.unicorn.Element;

public class EcoreDocumentUtil {

	private static final Map<String, WeakReference<Element>> ElementMap = new TreeMap<String, WeakReference<Element>>();

	public static void registerObject(Element e) {
		if (e != null)
			ElementMap.put(e.getId(), new WeakReference<Element>(e));
	}
	
	public static Element getElement(String ID) {
		WeakReference<Element> map = ID != null? ElementMap.get(ID.trim()) : null;
		if (map != null) {
			if (map.get() == null)
				ElementMap.put(ID,  null);
			return map.get();
		}
		return null;
	}

}
